//
//  MemberCardButton.m
//  Education
//
//  Created by mosn on 20/12/2016.
//  Copyright © 2016 yuyang. All rights reserved.
//

#import "MemberCardButton.h"

@interface MemberCardButton()
@property (strong,nonatomic) UILabel *lbTime;
@property (strong,nonatomic) UILabel *lbCurrent;
@property (strong,nonatomic) UILabel *lbPast;

@end

@implementation MemberCardButton

- (void)initMemberCardFrame:(CGRect)frame withTime:(NSString *)time CurrentMoney:(NSString *)current PastMoney:(NSString *)past{
    
    self.frame = frame;
    
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = [UIColor colorWithHexString:@"e2e3e5"].CGColor;
    self.layer.cornerRadius = 4;
    self.layer.masksToBounds = YES;
    
    self.lbTime = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 40, frame.size.height)];
    self.lbTime.backgroundColor = [UIColor clearColor];
    self.lbTime.textColor = [UIColor blackColor];
    self.lbTime.font = [UIFont systemFontOfSize:12];
    self.lbTime.text = time;
    [self addSubview:self.lbTime];
    
    int pastWidth = 60;
    if (past) {
        pastWidth = 60;
    }
    
    self.lbCurrent = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width-pastWidth-15, 5, 60, (frame.size.height-10)*0.5)];
//    if ([time isEqualToString:@"12个月"]) {
//        self.lbCurrent.frame = CGRectMake(frame.size.width-pastWidth-15, 0, 40, frame.size.height);
//    }else{
//        
//        self.lbCurrent.frame = CGRectMake(frame.size.width-pastWidth-15, 0, 35, frame.size.height);
//    }
    self.lbCurrent.textAlignment = NSTextAlignmentRight;
    self.lbCurrent.backgroundColor = [UIColor clearColor];
    self.lbCurrent.font = [UIFont systemFontOfSize:12];
    self.lbCurrent.textColor = RGBColor(255, 82, 20);
    self.lbCurrent.text = current;
    [self addSubview:self.lbCurrent];
    
    self.lbPast = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width-pastWidth-15, 5+(frame.size.height-10)*0.5, 60, (frame.size.height-10)*0.5)];
    self.lbPast.backgroundColor = [UIColor clearColor];
    self.lbPast.textAlignment = NSTextAlignmentRight;
    self.lbPast.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.lbPast];
    
    if (past) {
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:past];
        [attr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleThick) range:NSMakeRange(0, past.length)];
        self.lbPast.attributedText = attr;
    }else{
        
        self.lbCurrent.frame = CGRectMake(frame.size.width-pastWidth-15, 15, 60, frame.size.height-30);
    }
    
}

- (void)setSelected:(BOOL)selected{
    
    if (selected) {
        [self setBackgroundColor:[UIColor colorWithHexString:@"2BBBCB"]];
        self.lbTime.textColor = [UIColor whiteColor];
        self.lbCurrent.textColor = [UIColor whiteColor];
        self.lbPast.textColor = [UIColor lightGrayColor];
    }
    else{
        [self setBackgroundColor:[UIColor whiteColor]];
        self.lbTime.textColor = [UIColor colorWithHexString:@"999999"];
        self.lbCurrent.textColor = RGBColor(255, 82, 20);
        self.lbPast.textColor = [UIColor lightGrayColor];
    }
}

@end
